package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    private IWmChannelService wmChannelService;


    //   /list
    // 根据频道名称分页查询
    @PostMapping("/list")
    @ApiOperation(value = "listByName", notes = "根据频道名称分页查询")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", required = true, dataType = "ChannelDto")
    public ResponseResult listByName(@RequestBody ChannelDto dto){
        return wmChannelService.listByName(dto);
    }

    @PostMapping
    @ApiOperation(value = "saveChannel", notes = "保存频道")  // value指名称  notes 备注
    @ApiImplicitParam(name = "wmChannel", required = true, dataType = "WmChannel")
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel){
        return wmChannelService.saveChannel(wmChannel);
    }



    /**
     * 查询所有频道
     * @return
     */
    @GetMapping("/channels")
    @ApiOperation(value = "channels", notes = "查询所有频道")  // value指名称  notes 备注
    public ResponseResult channels(){
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }

}
